/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.p10.miage.gestionabsence.model;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author huynal
 */
public class AgendaAffichage {
    
    int idAgenda;
    String nomSalle;
    String nomEc;
    String ecDebut;
    String ecFin;

    public AgendaAffichage() {
    }

    public AgendaAffichage(int idAgenda, String salle, String ec, String ecDebut, String ecfin) {
        this.idAgenda = idAgenda;
        this.nomSalle = salle;
        this.nomEc = ec;
        this.ecDebut = ecDebut;
        this.ecFin = ecfin;
    }

    public String getEc() {
        return nomEc;
    }

    public void setEc(String ec) {
        this.nomEc = ec;
    }

    public String getEcDebut() {
        return ecDebut;
    }

    public void setEcDebut(String ecDebut) {
        this.ecDebut = ecDebut;
    }

    public String getEcfin() {
        return ecFin;
    }

    public void setEcfin(String ecfin) {
        this.ecFin = ecfin;
    }

    public int getIdAgenda() {
        return idAgenda;
    }

    public void setIdAgenda(int idAgenda) {
        this.idAgenda = idAgenda;
    }

    public String getSalle() {
        return nomSalle;
    }

    public void setSalle(String salle) {
        this.nomSalle = salle;
    }
    
    public void init(ResultSet resultat) throws SQLException{

    this.idAgenda = resultat.getInt("IDCR");    
    this.nomSalle = resultat.getString("salle");
    this.nomEc = resultat.getString("ec");
    this.ecDebut = resultat.getString("debut");
    this.ecFin = resultat.getString("fin");
    
    this.ecDebut = transformHoraire(this.ecDebut);
    this.ecFin = transformHoraire(this.ecFin);    
    }
    
    private String transformHoraire(String horaire)
    {
        String heure;
        String minute;
        if(horaire.length() == 3)
        {
            heure = horaire.substring(0,1);
            minute = horaire.substring(1,3);
            horaire = heure + "H" + minute;
        }
        else
        {
            heure = horaire.substring(0,2);
            minute = horaire.substring(2,4);
            horaire = heure + "H" + minute;
        }
        return horaire;
    }
       
}
